/**
 * Package für die GUI-Elemente
 */
package swa2012.telco.client.gui;
import swa2012.telco.broker.beans.*;
import swa2012.telco.client.gui.elements.*;
//import com.sun.xml.internal.ws.policy.privateutil.PolicyUtils.IO;

//import elements.*;

import java.net.URISyntaxException;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.Vector;
import swa2012.telco.client.*;
import swa2012.telco.provider.*;

/**
 * @author lukas schober
 * @date 20.05.2012
 */
public class TelcoClientGUI {

        /**
         * Konstruktor
         */

        public static String clientid = "kingkumi";
        //public static TelcoProvider provider = new TelcoProvider("group12");


        public TelcoClientGUI() {
        }


        /**
         * @param args
         * @throws URISyntaxException
         */
        public static void main(String[] args) throws URISyntaxException {

                guiGenerator gg = new guiGenerator();

                //TelcoClient tc = new TelcoClient(clientid, provider); //hier kommt das ClientObject

                //TelcoProvider provider = new TelcoProvider("group12");
                TelcoClient tc = new TelcoClient(clientid);

                for(Client c : tc.listClients()){
                        System.out.println(c.getID()+"@" + c.getProvider().getID());
                }

                //System.out.print(gg.getALLguiViewsString());

                Vector <String> input = new Vector<String>(); //0...Funktion, 1+...Parameter
                do{
                	input.clear();
                	Scanner sc = new Scanner(System.in);
                	System.out.println("Awayting your Command>");
	                String scresult = sc.nextLine();

	                if(scresult.contains(" ")){
	                        String[] tmp = scresult.split("\\s+");
	                        String message = "";

	                        for(int i = 0; i<tmp.length;i++){
	                                if(i>1){
	                                        message = message + " " +tmp[i];
	                                }else{
	                                        input.add(i, tmp[i]);
	                                }
	                        }
	                        input.add(2, message);
	                }else{
	                	input.add(0,scresult);
	                }

	                switch(input.get(0)){
//	                        case "connect":{
//	                                LinkedHashMap <String, String> vparam = new LinkedHashMap<String,String>();
//	                                vparam.put("#FROM", clientid);
//	                                vparam.put("#TO", input.get(1));
//
//	                                gg.setguiViews("CONNECT", vparam);
//
//	                                System.out.print(gg.getguiViewsString("CONNECT"));
//	                                break;
//	                                }
	                        case "list":{
	                                LinkedHashMap <String, String> vparam = new LinkedHashMap<String,String>();
	                                vparam = tc.listClientsString();

	                                gg.setguiViews("LISTUSERS", vparam);

	                                System.out.print(gg.getguiViewsString("LISTUSERS"));
	                                break;
	                        }
	                        case "sendto":{

	                        		tc.sendMessage(input.get(1), input.get(2));

	                                LinkedHashMap <String, String> vparam = new LinkedHashMap<String,String>();
	                                vparam.put("#FROM", clientid);
	                                vparam.put("#TO", input.get(1));
	                                vparam.put("#Message", input.get(2));

	                                gg.setguiViews("MESSAGESEND", vparam);

	                                System.out.print(gg.getguiViewsString("MESSAGESEND"));
	                                break;
	                        }
	                        case "disconnect":{
	                        		tc.disconnect();

	                                LinkedHashMap <String, String> vparam = new LinkedHashMap<String,String>();
	                                vparam.put("#FROM", clientid);
	                                vparam.put("#Message", "Bye!"); //hier fehlt was

	                                gg.setguiViews("DISCONNECT", vparam);

	                                System.out.print(gg.getguiViewsString("DISCONNECT"));
	                                break;
	                        }
	                        case "help":{
	                                System.out.print(gg.getguiViewsString("HELP"));
	                                break;
	                        }
	                        case "getmyM":{
	                        		Vector <LinkedHashMap<String,String>> mymessages = tc.getMessagesString();

	                        		for(LinkedHashMap<String,String> vparam: mymessages){
	                        			gg.setguiViews("MESSAGERECE", vparam);
	 	                                System.out.print(gg.getguiViewsString("MESSAGERECE"));
	                        		}

//	                        		LinkedHashMap <String, String> vparam = new LinkedHashMap<String,String>();
//	                                vparam.put("#FROM", clientid);
//	                                vparam.put("#TO", input.get(1));
//	                                vparam.put("#Message", input.get(2));
//
//	                                gg.setguiViews("MESSAGERECE", vparam);
//
//	                                System.out.print(gg.getguiViewsString("MESSAGERECE"));
                                	break;
	                        }
	                        default:{
	                                System.out.println("Ihre Eingabe war Fehlerhaft. Hier die Hilfe!");
	                                System.out.print(gg.getguiViewsString("HELP"));
	                                break;
	                        }
	                }

                }while(!input.get(0).equals("disconnect"));

        }
}
